package com.ysy.wiki.service;


import com.ysy.wiki.domain.Ebook;
import com.ysy.wiki.domain.EbookExample;
import com.ysy.wiki.mapper.EbookMapper;
import com.ysy.wiki.req.EbookReq;
import com.ysy.wiki.resp.EbookResp;
import com.ysy.wiki.util.CopyUtil;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class EbookService {
    @Resource
    private EbookMapper ebookMapper;

    public List<EbookResp>list(EbookReq req){
        EbookExample ebookExample = new EbookExample();

        EbookExample.Criteria criteria = ebookExample.createCriteria();

        criteria.andNameLike("%"+req.getName()+"%");
        List<Ebook> ebooksList = ebookMapper.selectByExample(ebookExample);

        /*List<EbookResp> respList = new ArrayList<>();

        for (Ebook ebook : ebooksList) {
          // EbookResp ebookResp= new EbookResp();

           // BeanUtils.copyProperties(ebook,ebookResp);
            EbookResp ebookResp = CopyUtil.copy(ebook, EbookResp.class);
            respList.add(ebookResp);
        }*/
        List<EbookResp> list =CopyUtil.copyList(ebooksList,EbookResp.class);
return list;
    }


}
